import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home'
import permission from './permission';
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/course',
    name: 'Course',
    component: () => import(/* webpackChunkName: "about" */ '../views/Course'),
    meta:{
      needLogin:true
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: () => import(/* webpackChunkName: "about" */ '../views/Profile')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "about" */ '../views/Login')
  },
  {
    path:'*',
    component:{
      render(){
        return <h1>找不到</h1>
      }
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 全局的权限判断操作
//把permission里的函数每个拿出来并放入beforeEach中
Object.values(permission).forEach(hook=>{
  router.beforeEach(hook.bind(router))
})


export default router
